﻿using System;
using System.Windows;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using SilverlightWebcamEncoder.Messages;

namespace SilverlightWebcamEncoder.ViewModels
{
    public class MainPageViewModel : ViewModelBase
    {
        private const string VISUALSTATE_Encoding = "Encoding";
        private const string VISUALSTATE_Playback = "Playback";
        private bool m_notOutofBrowser;
        private string m_visualState;

        public MainPageViewModel()
        {
            if (IsInDesignMode)
                NotOutofBrowser = false;
            else
                NotOutofBrowser = !Application.Current.IsRunningOutOfBrowser;

            Messenger.Default.Register<PlaybackClosed>(this, OnPlaybackClosed);
            Messenger.Default.Register<CapturedMediaReady>(this, OnCapturedMediaReady);
            Messenger.Default.Register<EncoderPrepared>(this, OnEncoderPrepared);
        }

        public void OnPlaybackClosed(PlaybackClosed e)
        {
            VisualState = VISUALSTATE_Encoding;
        }

        public void OnEncoderPrepared(EncoderPrepared e)
        {
        }

        public void OnCapturedMediaReady(CapturedMediaReady e)
        {
            VisualState = VISUALSTATE_Playback;
        }

        public bool NotOutofBrowser
        {
            get { return m_notOutofBrowser; }
            set
            {
                m_notOutofBrowser = value;
                RaisePropertyChanged("NotOutofBrowser");
            }
        }

        public string VisualState
        {
            get { return m_visualState; }
            set
            {
                m_visualState = value;
                RaisePropertyChanged("VisualState");
            }
        }
    }
}
